package com.lagou.service.impl;

import com.github.pagehelper.PageInfo;
import com.lagou.mapper.ArticleMapper;
import com.lagou.pojo.Article;
import com.lagou.service.ArticleService;
import com.lagou.service.PageRequest;
import com.lagou.service.PageResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author dell
 * @date 2020/9/29 17:28
 * @description
 */
@Service
public class ArticleServiceImpl implements ArticleService {

    @Resource
    private ArticleMapper articleMapper;
    @Override
    public Article selectArticle(Integer id) {
        return articleMapper.selectArticle(id);
    }

    @Override
    public PageResult findPage(PageRequest pageRequest) {
        return PageUtils.getPageResult(pageRequest, getPageInfo(pageRequest));
    }
    /**
     * 调用分页插件完成分页
     * @return
     */
    private PageInfo<Article> getPageInfo(PageRequest pageRequest) {
        int pageNum = pageRequest.getPageNum();
        int pageSize = pageRequest.getPageSize();
        Integer pageNow = pageNum * pageSize;
        List<Article> sysMenus = articleMapper.selectPage(pageNow,pageSize);
        return new PageInfo<Article>(sysMenus);
    }

}
